<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>品牌列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/index.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/index.js"></script>
    <script type="text/javascript" src="js/jquery.min.js"></script>

</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">报修管理</a>
            <a>
              <cite>报修列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" >

                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="repairContent"  placeholder="" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" onclick ="repair_query()" type="button" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    
                    <button class="layui-btn" onclick="xadmin.open('添加报修','repair-add.jsp',500,400)"><i class="layui-icon"></i>我要报修</button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form" id="table-repair">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                            </th>
                            <th>
                               报修编号
                            </th>
                            <th>
                                报修时间
                            </th>
                            <th>
                                报修内容
                            </th>
                            <th>
                                处理日期
                            </th>
                            <th>
                                报修状态
                            </th>
                            <th>
                                操作
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>
                                <input type="checkbox" name="id" value="1"   lay-skin="primary">
                            </td>
                            <td>
                                诺基亚
                            </td>

                            <td >
                                <a href="http://www.nokia.com.cn/">	http://www.nokia.com.cn/</a>
                            </td>

                            <td >
                                公司网站：http://www.nokia.com.cn/ 客服电话：...
                            </td>
                            <td>
                                10
                            </td>
                            <td class="td-status"> <span class="layui-btn layui-btn-normal " > 显示 </span>
                            </td>
                            <td class="td-manage">
                                <a style="text-decoration:none;/* pointer-events: none;cursor: default; */" onclick="member_stop(this,'10001')" href="javascript:;" title="未解决">
                                    <i class="layui-icon">&#xe605;</i>
                                </a>
                                <a title="删除" href="javascript:;" onclick="member_del(this,'1')"
                                   style="text-decoration:none">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>

                        </tbody>
                    </table>
                </div>

               <div class="layui-card-body " >
						<div class="page">
							<div class="layui-table-page">
								<div id="layui-table-page1">
									<div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-2">
										
									</div>
								</div>
							</div>
						</div>
				</div>

            </div>
        </div>
    </div>
</div>
</body>
<script>

	
	let pageNum = 1;
	let pageSize = 3;
	repair_search();
	function repair_search(){
		pageSize = $("#layui-laypage-2 select").val();
		if(pageSize == null){
			pageSize = 3;	
		}
		
		$.ajax({
			async:true,
			type:"get",
			url:"${pageContext.request.contextPath}/RepairServlet",
			data:{
				op:"ownerRepairList",
				phoneNumber:"${sessionScope.ownerSession.ownerPhoneNumber}",
				repairContent:$("input[name='repairContent']").val(),
				pageNum:pageNum,
				pageSize:pageSize
			},
			contentType:"application/x-www-form-urlencoded",
			dataType:"json",
			success:function(result,status,xhr){
				
				let content = "";
				if(result.data != null){
					$.each(result.data.list,function(index, obj) {
						let isShelf = "";
						let repairDealTime = "";
						if(obj.repairDealTime == null || "" == obj.repairDealTime ){
							repairDealTime = "暂无时间";
						}else{
							repairDealTime = obj.repairDealTime.replace("T"," " );
						}
						if("02"==obj.repairStatus){
							isShelf = "<td class=\"td-status\"><span class=\"layui-btn layui-btn-danger \"> 已受理 </span></td>";
						}else if("01"==obj.repairStatus){
							isShelf = 
				           		"<td class=\"td-status\"><span class=\"layui-btn layui-btn-normal \"> 未受理 </span></td>";
						}else if("03"==obj.repairStatus){
							isShelf = 
				           		"<td class=\"td-status\"><span class=\"layui-btn layui-btn-warm \"> 已维修 </span></td>";
						}
						
						content += "<tr>"+
                        "<td>"+
                            "<input type=\"checkbox\" name=\"id\" value=\"1\"   lay-skin=\"primary\">"+
                        "</td>"+
                        "<td>"+obj.repairNO+"</td>"+

                        "<td>"+obj.repairCreateTime.replace("T"," ")+"</td>"+

                        "<td>"+obj.repairContent+"</td>"+
                        "<td>"+repairDealTime+"</td>"+
                        isShelf+																						
                        "<td class=\"td-manage\">"+
                            "<a style=\"text-decoration:none;/* pointer-events: none;cursor: default; */ \" status=\""+obj.repairStatus+"\" onclick=\"member_stop(this,'"+obj.repairNO+"')\" href=\"javascript:;\" title=\"未解决\">"+
                                "<i class=\"layui-icon\">&#xe605;</i>"+
                            "</a>"+
                            "<a title=\"删除\" href=\"javascript:;\" onclick=\"member_del(this,'"+obj.repairNO+"','"+obj.repairStatus+"')\" style=\"text-decoration:none\">"+
                                "<i class=\"layui-icon\">&#xe640;</i>"+
                            "</a>"+
                        "</td>"+
                    "</tr>"
					});
					$("#table-repair tbody").html(content);
				}else{
					$("#table-repair tbody").empty();
				}
				//渲染分页栏目
				let pageContent="";
				if(result.data != null){
					
					//判断是不是第一页
					if(result.data.pageNum == 1){
						pageContent="<a href=\"javascript:;\" class=\"layui-laypage-prev layui-disabled\" data-page=\"0\"><i class=\"layui-icon\">上一页</i></a>";
					}else{
						pageContent="<a href=\"javascript:;\" class=\"layui-laypage-prev\" data-page=\""+(result.data.pageNum-1)+"\"><i class=\"layui-icon\">上一页</i></a>";
					}
					for(let i=1;i<=result.data.pages;i++){
						//判断当前页码
						if(i == result.data.pageNum){
							pageContent+="<span class=\"layui-laypage-curr\" data-page=\""+i+"\"><em class=\"layui-laypage-em\"></em><em>"+i+"</em></span>";
						}else{
							pageContent+="<a href=\"javascript:;\" data-page=\""+i+"\">"+i+"</a>";
						}
						
						
					} 
					
				 //判断是否是最后一页
				 if(result.data.pageNum == result.data.pages){
					 pageContent += "<a href=\"javascript:;\" class=\"layui-laypage-next layui-disabled\" data-page=\""+(result.data.pageNum+1)+"\"><i class=\"layui-icon\">下一页</i></a>";
				 }else{
					 pageContent += "<a href=\"javascript:;\" class=\"layui-laypage-next\" data-page=\""+(result.data.pageNum+1)+"\"><i class=\"layui-icon\">下一页</i></a>"
				 }
				 
				 pageContent +=	"<span class=\"layui-laypage-limits\">"+
				 				"<select lay-ignore=\"\">"+
				 				"<option value=\"3\" >3条/页</option>"+
				 				"<option value=\"5\">5 条/页</option>"+
				 				"<option value=\"10\">10 条/页</option>"+
				 				"</select></span>";
					$("#layui-laypage-2").html(pageContent);
					
					$("#layui-laypage-2 select option").each(function(){
						if($(this).val() == result.data.pageSize){
							$(this).prop("selected","selected");
						}
					});
				}else{
					$("#layui-laypage-2").html(pageContent);
				}
			},
			error:function(){
				alert("异步请求失败");
			}
		});
		
}
	
	//点击页数
	$("#layui-table-page1").on("click","#layui-laypage-2 a",function(){
		pageNum = $(this).data("page");
		repair_search();
	});

	

	//条数下拉框事件
	$("#layui-table-page1").on("change","#layui-laypage-2 select",function(){
		//设置页码数
		pageNum = 1;
		repair_search();
	});


	//点击搜索

	function repair_query(){
		pageNum = 1;
		repair_search();
	}
</script>
<script>


	
	

    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;


        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });


    });

    /*用户-添加*/
    function member_add(title,url,id,w,h){

        xadmin.open(title,url,id,w,h);
    }

    /*用户-停用*/
    function member_stop(obj,repairNo){
    	if($(obj).attr('status') != 03){
	        layer.confirm('确认已解决吗？',{icon:3,title:'提示信息'},function(index){

	        	//异步修改
	        	$.getJSON("${pageContext.request.contextPath}/RepairServlet",{
	        		op:"ownerRepairStatusUpdate",
	        		repairNo:repairNo,
	        		repairStatus:"03"
	        	},function(result,status,xhr){
	        		if(result.data == true){
   	        			layui.use('layer',function(){
   	        				layer.msg('已解决!',{icon:1,time:3000});
   	        			});
   	        											   
   	        			//设置页码
   	        			pageNum = $("#layui-laypage-2 span.layui-laypage-curr").data("page");
   	        			repair_search();
	        		}
	        	});
	        	
	                //发异步把用户状态进行更改
	                $(obj).attr('status','03')
	               
	               // layer.msg('已解决!',{icon: 1,time:1000});
	
	          
	
	        });
    	}else {
    	  
              
              layer.msg('报修状态为已解决！请勿重复点击!',{icon: 5,time:1000});
          
    	}
    }

    /*用户-删除*/
    function member_del(obj,repairNo,status){
    	if(status != 02){
    		 layer.confirm('确认要删除吗？',{icon:3,title:'提示信息'},function(index){
    			 $.getJSON("${pageContext.request.contextPath}/RepairServlet",{repairNo:repairNo,op:"repairDelete"},function(result,status,xhr){
    				 if(result.data == true){
    	        			layui.use('layer',function(){
    	        				layer.msg(result.message,{icon:1,time:3000});
    	        			});
    	        											   
    	        			//设置页码
    	        			pageNum = $("#layui-laypage-2 span.layui-laypage-curr").data("page");
    	        			repair_search();
    	        		}else{
    	        			layui.use('layer',function(){
    	        				layer.msg(result.message,{icon:2,time:3000});
    	        			});
    	        		}
    			 });
    	            layer.msg('已删除!',{icon:1,time:1000});
    	        });
    	}else{
    		 layer.msg('受理中不可删除!',{icon:5,time:1000});
    	}
       
    }



    function delAll (argument) {
        var ids = [];

        // 获取选中的id
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
                ids.push($(this).val())
            }
        });

        layer.confirm('确认要删除吗？'+ids.toString(),{icon:3,title:'提示信息'},function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
</html>